package admin.forms;

import helpers.UrlHelper;

import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;

import entities.Domain;

import admin.models.DomainModel;

public class DomainForm {
	public static TreeMap checkValidDomain(HttpServletRequest request) {
		TreeMap form = new TreeMap();
		TreeMap check = new TreeMap();
		
		String domainName = (String) request.getParameter("domain");
		
		if (!UrlHelper.checkDomain(domainName)) {
			check.put("domain", "Domain is not valid.");
		}
		
		DomainModel domainModel = DomainModel.getInstance();
		Domain domain = domainModel.get(domainName);
		if (domain == null) {
			check.put("domain", "Domain not exists.");
			domain = new Domain();
		} else {
			if (domain.getStatus() == -1) {
				check.put("domain", "Domain has been in blacklist.");
			}
		}
		
		form.put("checkValid", check);
		form.put("domain", domain);
		
		return form;
	}
}
